import axios from 'axios'
import Message from '@/components/msg/msg'
axios.interceptors.request.use((req) => {
  console.log(req.url)
  const token = localStorage.getItem('LoginToken')
  if (token !== null) {
    //浏览器将带有token的请求发送到服务器端
    req.headers && (req.headers.Authorization = token)
  }
  return req
})
axios.interceptors.response.use(
  (res) => {
    if (res.data.error !== -1 && res.data.message) {
      Message.error(res.data.message)
    }

    return res
  },
  (err) => {
    // console.log(err)
    // if(localStorage.getItem("LoginToken")){
    //   localStorage.removeItem("LoginToken")
    //   this.$store.dispatch("setUser",{
    //     username:"",
    //     avatar:"",
    //     status:0,
    //     id:"",
    //     realname:""
    //   })
    //   this.$store.dispatch("setToken",false)
    // }
    // alert("请重新登录(或是服务器出错了。。。)")
  }
)

// axios.defaults.baseURL = 'http://localhost:3001/api'
// axios.defaults.baseURL = 'https://www.ttzxh.icu/api'
// axios.defaults.baseURL="https://101.34.49.149/api"
// const baseURL = 'http://127.0.0.1:8080/api'
const socketURL = 'wss://www.ttzxh.icu/api'
const baseURL = 'https://www.ttzxh.icu/api'
// const socketURL = 'ws://127.0.0.1:8089/api'
// const baseURL = 'http://localhost:8089/api'
axios.defaults.baseURL = baseURL
export { baseURL }
export { socketURL }

axios.defaults.timeout = 1800000
export default axios
